<%--
  Created by IntelliJ IDEA.
  User: Enpi
  Date: 2021/9/3
  Time: 19:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String ctx = request.getContextPath();
    request.setAttribute("ctx", ctx);
%>
<link href="<%=request.getContextPath()%>/css/css.css" rel="stylesheet">
<html>
<head>
    <title>DDQ</title>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>Bootstrap</title>
    <%--    <link rel="stylesheet" type="text/css" href="css/css.css"/>--%>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/bootstrap/bootstrap.css">
    <script type="text/javascript" src="<%=request.getContextPath()%>/bootstrap/jquery-1.9.1.min.js"></script>
    <script src="<%=request.getContextPath()%>/bootstrap/bootstrap.js"></script>
    <script src="<%=request.getContextPath()%>/bootstrap/jquery.validate.min.js"></script>
    <script src="<%=request.getContextPath()%>/bootstrap/validate.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/My97DatePicker/WdatePicker.js"></script>

</head>
<body>
<form action="/list.do" method="post">
    <input type="hidden" name="cpage">
    名称模糊:<input type="text" value="${map.mohu}">

    <select name="xiala">
        <option value="">请选择</option>
        <option value="s.sid" ${map.xiala=='s.sid'?'selected':''} >编号</option>
        <option value="starttime" ${map.xiala=='starttime'?'selected':''} >时间</option>
    </select>
    <select name="xulie">
        <option value="">请选择</option>
        <option value="asc"  ${map.xulie=='asc'?'selected':''} >正序</option>
        <option value="desc" ${map.xulie=='desc'?'selected':''} >倒叙</option>
    </select>
    <input type="submit" value="查询">


    <input type="submit">
</form>

<input type="button" value="全选" onclick="qx()">
<input type="button" value="全不选" onclick="qbx()">
<input type="button" value="反选" onclick="fx()">
<input type="button" value="批删" onclick="dels(${s.sid})">
<table>
    <tr>
        <td>编号</td>
        <td>名称</td>
        <td>省</td>
        <td>市</td>
        <td>县</td>
        <td>图片</td>
        <td>状态</td>
        <td>介绍</td>
        <td>时间</td>
        <td>bid</td>
        <td>
            <input type="button" value="添加" onclick="add()">
        </td>
    </tr>
    <c:forEach items="${pageInfo.list}" var="s">
        <tr>
            <td><input type="checkbox" name="sid" value="${s.sid}"> </td>
            <td>${s.sid}</td>
            <td>${s.sname}</td>
            <td>${s.shengname}</td>
            <td>${s.shiname}</td>
            <td>${s.xianname}</td>
            <td>
                <img src="${s.pic}" alt="无法展示" width="100px">
            </td>
            <td>${s.status==0?"上架":"下架"}</td>
            <td>${s.title}</td>
            <td>${s.starttime}</td>
            <td>${s.bnames}</td>
            <td>
                <input type="button" value="修改" onclick="upd(${s.sid})">
                <input type="button" value="删除" onclick="del(${s.sid})">
            </td>
        </tr>
    </c:forEach>
</table>
<tr>
    <td><input type="button" value="首页" onclick="fenye(1)"> </td>
    <td><input type="button" value="上一页" onclick="fenye(${pageInfo.isFirstPage?1:pageInfo.prePage})"> </td>
    <td><input type="button" value="下一页" onclick="fenye(${pageInfo.isLastPage?pageInfo.pages:pageInfo.nextPage})"> </td>
    <td><input type="button" value="尾页" onclick="fenye(${pageInfo.pages})"> </td>
</tr>
</body>
<script>
    function fenye(cpage) {
        $("[name='cpage']").val(cpage);
        $("form").submit();
    }
    function add() {
        location="toadd.do";
    }
    function upd(sid) {
        location="toupd.do?sid="+sid;
    }

    function qx() {
        $("[name='sid']").prop("checked",true)
    }

    function qbx() {
        $("[name='sid']").prop("checked",false)
    }

    function fx() {
        $("[name='sid']").each(function () {
            $(this).prop("checked",!$(this).prop("checked",))
        })
    }

    function dels() {
        var sid = "";
        $("[name='sid']:checked").each(function () {
            var a =$(this).val()
            sid+=","+a
        })
        sid = sid.substring(1)
        $.ajax({
            type: "post",
            url: "dels.do",
            data: {"sid":sid},
            dataType:"json",
            success: function (res) {
                if (res>0){
                    alert("劈山成功")
                    location="list.do"
                }
            }
        })
    }

    function del(sid) {
        $.ajax({
            type: "post",
            url: "del.do",
            data: {"sid":sid},
            dataType:"json",
            success: function (res) {
                if(res>0){
                    alert("删除成功")
                    location="list.do"
                }
            }
        })
    }
</script>
</html>
